package com.atguigu.stgy.admin.controller;

import com.atguigu.stgy.admin.service.LabelInfoService;
import com.atguigu.stgy.model.entity.LabelInfo;
import com.atguigu.stgy.admin.service.impl.LabelInfoServiceImpl;
import com.atguigu.stgy.model.entity.LeaseTerm;
import com.atguigu.stgy.model.enums.LabelTypeEnum;
import com.atguigu.stgy.model.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//

/**
 * 标签信息表(label_info)表控制层
 *
 * @author xxxxx
 */
@RestController
@Tag(name = "标签管理模块")
@RequestMapping("/admin/label")
public class LabelInfoController {
    /**
     * 服务对象
     */
    @Resource
    private LabelInfoService labelInfoService;

    @GetMapping("list")
    @Operation(summary = "根据类型查询标签列表")
    public R<List<LabelInfo>> list(@RequestParam(required = false)LabelTypeEnum type){
        //待条件查询标签列表
        List<LabelInfo> labelInfos = labelInfoService.listLablesByType(type);
        return R.ok(labelInfos);
    }

    @Operation(summary = "删除指定标签")
    @DeleteMapping("/deleteById")
    public R deleteById(@RequestParam("id")Long id){
        labelInfoService.removeById(id);
        return R.ok();
    }
    @Operation(summary = "新增或更新标签")
    @PostMapping("/saveOrUpdate")
    public R saveOrUpdate(@RequestBody LabelInfo labelInfo){
        labelInfoService.saveOrUpdate(labelInfo);
        return R.ok();
    }
}